{extend name="base"/}
{block name="title"}
   收货地址
{/block}
{block name="css"}
<link rel="stylesheet" href="__MOBILE__/css/wy.css">
<style>
    body,html{
     background:#f5f5f5;
    }
    .header_mess{float: right;width: 20%;height: 1rem;text-align:center;margin-top:.3rem;}
</style>
{/block}
{block name="content"}
<!-- 头部 -->
<div class="head">
        <div class="head_left">
            <a href="javascript:history.go(-1);"><img src="__MOBILE__/images/true.png" alt=""></a>
        </div>
        <div class="head_con">{:lang('地址管理')}</div>
        <div class="header_mess"> <a href="{:url('/langjinmobile/merchandise/addresseditor')}">添加</a></div>
    </div>
<!-- 内容部分 -->
<ul>
{volist name='add_list' id='vo'}
<li class="bu_addresscontent" style="margin-top:1.2rem;">
        <a href="/langjinmobile/Merchandise/addresseditor/id/{$vo.id}" class="bu_addressname">{$vo.username}</a>
        <span class="bu_adresstel">{$vo.mobile}</span>
        <a href="/langjinmobile/Merchandise/addresseditor/id/{$vo.id}" class="bu_receiveadress">
            地址：{$vo.province}{$vo.city}{$vo.area}{$vo.street}{$vo.address}        </a>
        <div class="bu_setting">
                <span class="all_pitch_on {if $vo.attribute eq 1}isActive{/if}" onclick = "check_default({$vo.id})"></span>&nbsp;&nbsp;默认            
            <div class="bu_setdel">
                <img src="/static/shop/images/store/del.png" alt="">
                <span class="bu_del" onclick="del({$vo.id})">删除</span>
            </div>
        </div>
    </li>
{/volist}
   <!--  <li class="bu_addresscontent" >
            <a href="/shop/address/address/id/29" class="bu_addressname">伊利</a>
            <span class="bu_adresstel">11111111111111</span>
            <a href="/shop/address/address/id/29" class="bu_receiveadress">
                地址：法定方粉底卅高富帅国防生的方式发光飞碟        </a>
            <div class="bu_setting">
                    <span class="all_pitch_on"></span>&nbsp;&nbsp;默认                
                <div class="bu_setdel">
                    <img src="/static/shop/images/store/del.png" alt="">
                    <span class="bu_del" onclick="del(29)">删除</span>
                </div>
            </div>
        </li> -->
    </ul>
<!-- 底部 -->
{/block}
{block name="js"}
<script>
        //Demo
        layui.use('form', function(){
          var form = layui.form;
          
          //监听提交
          form.on('submit(formDemo)', function(data){
            layer.msg(JSON.stringify(data.field));
            return false;
          });
        });
 </script>
 <script>
$(".all_pitch_on").click(function(){
        var Oindex = $(this).parent().parent().index();
        $(".all_pitch_on ").removeClass("isActive").eq(Oindex).addClass("isActive");
    });
</script>

<script type="text/javascript">
        //删除收货地址
    function del(id){
        layer.confirm("确定要删除吗？", {icon: 3, title:'提示'}, function(index){
            $.post('/langjinmobile/Merchandise/del_address',{'id':id},function(data){
                if(data.status == 1){
                    layer.msg(data.msg, {
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function(){
                       location.reload();
                    });
                }else{
                    layer.msg(data.msg);
                }
            })

            layer.close(index);
        });

    }
    //设置默认收货地址
    function check_default(id){
        $.post('/langjinmobile/Merchandise/check_default',{'id':id},function(data){

            if(data.status == 3){
                console.log(data);
            }else if(data.status == 1){
                layer.msg(data.msg, {
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                }, function(){
                    if(data.url)
                    {
                        window.location.href = data.url;
                    }else {
                        location.reload();
                    }
                });
            }else{
                layer.msg(data.msg);
            }
        })
    }
    //新增收货地址
    function increase_address(){
        var username = $("input[name='username']").val();
        var mobile = $("input[name='mobile']").val();
        var province = $("input[name='province']").val();
        var city = $("input[name='city']").val();
        var area = $("input[name='area']").val();
        var street = $("input[name='street']").val();
        var address = $(".textarea").html();
        var id = $("input[name='id']").val();
        //alert(id);
        if(username == '' || mobile == '' || province == '' || city == '' || area == '' || street == '' || address == '' ){
            layer.msg('请填写完整信息');
            return false;
        }else{
            if(id == null || id === undefined || id == ''){
                $.post('/shop/address/address',{'username':username,'mobile':mobile,'province':province,'city':city,'area':area,'street':street,'address':address},function(data){

                    if(data.status == 1){
                        layer.msg(data.msg, {
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        }, function(){
                            window.location.href = "/shop/address/index";
                        });
                    }else{
                        layer.msg(data.msg);
                    }
                })
            }else{
                $.post('/shop/address/edit_address',{'username':username,'mobile':mobile,'province':province,'city':city,'area':area,'street':street,'address':address,'id':id},function(data){

                    if(data.status == 1){
                        layer.msg(data.msg, {
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        }, function(){
                            window.location.href = "/shop/address/index";
                        });
                    }else{
                        layer.msg(data.msg);
                    }
                })
            }
        }


    }

</script>

{/block}